<template>
	<view class="agreement-popup" v-if="show">
		<view class="agreement-mask" @click="handleClose"></view>
		<view class="agreement-content">
			<view class="agreement-header">
				<text class="title">借款服务协议</text>
				<text class="close" @click="handleClose">×</text>
			</view>
			<scroll-view class="agreement-body" scroll-y>
				<view class="agreement-text">
					<view class="section">
						<view class="section-title">
							<text class="number">一</text>
							<text class="text">借款信息及声明</text>
						</view>
						<view class="section-content">
							<view class="content-item">
								1.1 借款金额：以实际申请金额为准，最高不超过授信额度
							</view>
							<view class="content-item">
								1.2 借款期限：以实际选择期限为准，包括7天、14天、30天、90天、180天、360天等多种期限
							</view>
							<view class="content-item">
								1.3 借款用途：仅限个人消费，不得用于非法用途或从事违法活动
							</view>
							<view class="content-item">
								1.4 借款人声明：本人具有完全民事行为能力，所提供的信息真实有效
							</view>
						</view>
					</view>
					<view class="section">
						<view class="section-title">
							<text class="number">二</text>
							<text class="text">还款规则及责任</text>
						</view>
						<view class="section-content">
							<view class="content-item">
								2.1 还款方式：一次性还本，到期全额还款
							</view>
							<view class="content-item">
								2.2 还款日期：以实际放款日期加上借款期限为准
							</view>
							<view class="content-item">
								2.3 提前还款：支持提前还款
							</view>
							<view class="content-item">
								2.4 逾期责任：请按时还款，避免影响个人信用记录
							</view>
						</view>
					</view>
					<view class="section">
						<view class="section-title">
							<text class="number">三</text>
							<text class="text">用户权利及义务</text>
						</view>
						<view class="section-content">
							<view class="content-item">
								3.1 用户有权了解借款的各项服务信息
							</view>
							<view class="content-item">
								3.2 用户有权在借款期限内自主选择还款时间
							</view>
							<view class="content-item">
								3.3 用户应当遵守平台的各项规则和要求
							</view>
							<view class="content-item">
								3.4 用户应当保护个人账户安全，防止信息泄露
							</view>
						</view>
					</view>
					<view class="section">
						<view class="section-title">
							<text class="number">四</text>
							<text class="text">隐私保护</text>
						</view>
						<view class="section-content">
							<view class="content-item">
								4.1 平台承诺对用户信息严格保密
							</view>
							<view class="content-item">
								4.2 未经用户同意，不向第三方提供用户信息
							</view>
							<view class="content-item">
								4.3 采用业内领先的安全技术保护用户数据
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
			<view class="agreement-footer">
				<button class="confirm-btn" @click="handleConfirm">
					<text class="btn-text">我已阅读并同意</text>
				</button>
			</view>
		</view>
	</view>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue'

const props = defineProps({
	show: {
		type: Boolean,
		default: false
	}
})

const emit = defineEmits(['close', 'confirm'])

const handleClose = () => {
	emit('close')
}

const handleConfirm = () => {
	emit('confirm')
	handleClose()
}
</script>

<style lang="scss" scoped>
.agreement-popup {
	position: fixed;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	z-index: 999;
}

.agreement-mask {
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	background: rgba(0, 0, 0, 0.4);
}

.agreement-content {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 85%;
	max-width: 600rpx;
	max-height: 85vh;
	background: #fff;
	border-radius: 20rpx;
	overflow: hidden;
	box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.12);
	display: flex;
	flex-direction: column;
}

.agreement-header {
	position: relative;
	padding: 24rpx 30rpx;
	text-align: center;
	border-bottom: 1rpx solid #eee;
	background: linear-gradient(to right, #f8f8f8, #fff, #f8f8f8);
	flex-shrink: 0;
	
	.title {
		font-size: 32rpx;
		font-weight: bold;
		color: #333;
		letter-spacing: 1rpx;
	}
	
	.close {
		position: absolute;
		right: 30rpx;
		top: 50%;
		transform: translateY(-50%);
		font-size: 40rpx;
		color: #999;
		width: 60rpx;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
		
		&:active {
			background: rgba(0, 0, 0, 0.05);
			border-radius: 50%;
		}
	}
}

.agreement-body {
	flex: 1;
	min-height: 200rpx;
	max-height: calc(85vh - 180rpx);
	padding: 30rpx;
	box-sizing: border-box;
	
	.section {
		margin-bottom: 30rpx;
		
		&:last-child {
			margin-bottom: 0;
		}
		
		.section-title {
			display: flex;
			align-items: center;
			gap: 16rpx;
			margin-bottom: 24rpx;
			
			.number {
				width: 40rpx;
				height: 40rpx;
				background: #4A90E2;
				color: #fff;
				font-size: 24rpx;
				line-height: 40rpx;
				text-align: center;
				border-radius: 8rpx;
				flex-shrink: 0;
			}
			
			.text {
				font-size: 30rpx;
				font-weight: bold;
				color: #333;
			}
		}
		
		.section-content {
			padding-left: 56rpx;
			
			.content-item {
				font-size: 28rpx;
				color: #666;
				line-height: 1.6;
				margin-bottom: 20rpx;
				position: relative;
				padding-right: 20rpx;
				word-break: break-all;
				white-space: normal;
				
				&:last-child {
					margin-bottom: 0;
				}
			}
		}
	}
}

.agreement-footer {
	padding: 24rpx 30rpx;
	border-top: 1rpx solid #eee;
	background: linear-gradient(to right, #f8f8f8, #fff, #f8f8f8);
	flex-shrink: 0;
	
	.confirm-btn {
		background: #4A90E2;
		color: #fff;
		border-radius: 45rpx;
		font-size: 30rpx;
		height: 80rpx;
		line-height: 80rpx;
		letter-spacing: 1rpx;
		transition: all 0.3s ease;
		
		&:active {
			transform: scale(0.98);
			background: darken(#4A90E2, 5%);
		}
		
		.btn-text {
			display: inline-block;
			vertical-align: middle;
		}
	}
}

@media screen and (max-height: 600px) {
	.agreement-content {
		max-height: 90vh;
	}
	
	.agreement-body {
		max-height: calc(90vh - 160rpx);
	}
	
	.agreement-header,
	.agreement-footer {
		padding: 20rpx 30rpx;
	}
	
	.confirm-btn {
		height: 70rpx !important;
		line-height: 70rpx !important;
	}
}
</style> 